package wowraidmanager.client.wishlist.admin;

import java.util.ArrayList;

import wowraidmanager.client.service.wishlist.RaidbossDroplistService;
import wowraidmanager.client.service.wishlist.RaidbossDroplistServiceAsync;
import wowraidmanager.client.wishlist.utils.RaidbossDroplistUtil;
import wowraidmanager.shared.model.wishlist.RaidbossDroplist;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.TabPanel;
import com.google.gwt.user.client.ui.Widget;

public class ImportlistGameVersion extends Composite{

    private static ImportlistUiBinder uiBinder = GWT.create(ImportlistUiBinder.class);

    protected RaidbossDroplistServiceAsync raidbossDroplistService = GWT.create(RaidbossDroplistService.class);

    interface ImportlistUiBinder extends UiBinder<Widget, ImportlistGameVersion>{
    }

    ArrayList<RaidbossDroplist> raodbossDroplist;

    @UiField
    TabPanel gameVersionTab;

    public ImportlistGameVersion(){
        initWidget(uiBinder.createAndBindUi(this));
        setTabPanel();
    }

    private void setTabPanel(){
        raidbossDroplistService.getRaidbossDroplist(new AsyncCallback<ArrayList<RaidbossDroplist>>(){

            public void onSuccess(ArrayList<RaidbossDroplist> result){
                raodbossDroplist = result;
                setGameversionTab();
            }

            public void onFailure(Throwable caught){
                // TODO 自動生成されたメソッド・スタブ

            }
        });

    }

    protected void setGameversionTab(){
        ArrayList<String> gameVersionList = RaidbossDroplistUtil.getGameversion(raodbossDroplist);

        for(String gameVersion:gameVersionList){
            ArrayList<RaidbossDroplist> newRaidbossdroplist = RaidbossDroplistUtil.getRaidbossdroplistGameVersion(raodbossDroplist, gameVersion);
            gameVersionTab.add(new ImportlistRaidzone(gameVersion, newRaidbossdroplist), gameVersion);
        }
        gameVersionTab.selectTab(0);
    }
}
